<?php

namespace Rainrock\Framework\Module;


use Rainrock\Framework\kernel\core\ModuleListener;
use Rainrock\Framework\kernel\Html\HtmlButton;
use Rainrock\Framework\kernel\Html\HtmlFun;
use Rainrock\Framework\kernel\Html\HtmlLabel;
use Rainrock\Framework\kernel\base\Jiami;
use Rainrock\Framework\kernel\base\File;

class SyslogModuleListener extends ModuleListener{
	
	public function onListRightbtn($pnum)
	{
		$btn[] = HtmlButton::gets()->addCont('清空日志')->setClickevt('clearall')->addCss('webbtn-default');
		return $btn;
	}
	
	public function onListScript()
	{
		$barr['clearall']	= HtmlFun::get()->addCode('this.query(\'clearall\')');
		$barr['tablecans'] 	= array('checked'=>true);
		return $barr;
	}
	
	public function onReplacers($rs, $lx)
	{
		if($rs['level']==3)$rs['trfontcolor'] = 'red';
		if($rs['level']==4){
			$rs['trfontcolor'] = '#ff6600';
			$rs['remark'] .= HtmlLabel::get('a')->addCont('[详情]')->setHref('javascript:;')->setonClick('js.open(\'?m=adminmanage&a=syslog&file='.Jiami::base64encode($rs['remark']).'\')')->show();
		}
		return $rs;
	}
	
	public function clearall()
	{
		$this->model->delete('1=1');
		$paths  = ''.ROOT_PACK.'/logs/list';
		File::getFolder($paths, function($file, $path){
			@unlink(''.$path.'/'.$file.'');
			return null;
		});
		return $this->returnsuccess();
	}
}